// NetCtrlForm.cpp : implementation file
//

#include "stdafx.h"
#include "WorkBench.h"
#include "NetCtrlForm.h"
//#include "ne"


// CNetCtrlForm dialog

IMPLEMENT_DYNAMIC(CNetCtrlForm, CBaseForm)

CNetCtrlForm::CNetCtrlForm(CWnd* pParent /*=NULL*/)
: CBaseForm(CNetCtrlForm::IDD, pParent)
{
}

CNetCtrlForm::~CNetCtrlForm()
{
}

void CNetCtrlForm::DoDataExchange(CDataExchange* pDX)
{
	CBaseForm::DoDataExchange(pDX);
	DDX_ManagedControl(pDX,IDC_STATIC_WINCTL2,m_ctrl);
}


BEGIN_MESSAGE_MAP(CNetCtrlForm, CBaseForm)
	ON_WM_SIZE()
	ON_WM_CREATE()
	ON_WM_LBUTTONDBLCLK()
END_MESSAGE_MAP()

CString CNetCtrlForm::GetTitle() const
{
	if(m_ctrl.GetSafeHwnd() != NULL)
	{
		CString title = m_ctrl->GetHoldControlTitle();
		if(title != _T(""))
			return title;
	}

	return m_actioninfo.ActionName;
}


CWinFormsControl<UCNetCtrlContainer>& CNetCtrlForm::GetCtrl()
{
	return m_ctrl;
}

void CNetCtrlForm::OnSize( UINT nType, int cx, int cy )
{
	CBaseForm::OnSize(nType, cx, cy);

	RECT rect;
	this->GetClientRect(&rect);
	if ( ::IsWindow(this->m_ctrl.GetSafeHwnd()) )
	{		
		rect.top = rect.top +60;		
		rect.bottom = rect.bottom > rect.top ? rect.bottom : rect.top;
		this->m_ctrl.MoveWindow(&rect,FALSE);
	}	
}
void CNetCtrlForm::FloatWindow()
{
	Tigera::UICommon::FormContainer^ form = gcnew Tigera::UICommon::FormContainer();
	System::Windows::Forms::Control^ ctl = this->m_ctrl->GetHoldCtrl();
	ctl->Parent = form;
	form->SetControl(ctl);

	IWin32Window^ w =  gcnew WindowWrapper( System::IntPtr( AfxGetMainWnd()->GetSafeHwnd() ) );

	form->Show(w);
}




BOOL CNetCtrlForm::OnInitDialog()
{
	CBaseForm::OnInitDialog();

	if( !m_actioninfo.ActionName.IsEmpty()  && !m_actioninfo.FuncName.IsEmpty())
	{		
		if( !this->m_ctrl->SetControl(m_actioninfo))
		{
			m_bSuccessed = FALSE;
			return FALSE;
		}
		else
		{
			m_bSuccessed = TRUE;
		}
	}

	return TRUE;  

}

bool CNetCtrlForm::SetAction( const ActionInfo& info )
{
	m_actioninfo =  info;
	return true;
}


int CNetCtrlForm::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (CBaseForm::OnCreate(lpCreateStruct) == -1)
		return -1;
	return 0;
}

BOOL CNetCtrlForm::OnCloseMsgRecieved()
{
	//throw std::exception("The method or operation is not implemented.");
	return TRUE;
}

void CNetCtrlForm::OnLButtonDblClk(UINT nFlags, CPoint point)
{
	// TODO: Add your message handler code here and/or call default

	CBaseForm::OnLButtonDblClk(nFlags, point);
	FloatWindow();
	this->GetParent()-> CloseWindow();
}
